
//登录页面跳转到注册页面
function jump1(){
    let lo=document.getElementsByClassName('login')[0];
    let en=document.getElementsByClassName('enroll')[0];
    lo.style.display='none';
    en.style.display='flex';
}

//注册页面跳转到登录页面
function jump2(){
    let lo=document.getElementsByClassName('login')[0];
    let en=document.getElementsByClassName('enroll')[0];
    lo.style.display='flex';
    en.style.display='none';
}

//点击 用户登录和管理员登录之间的小变化
function tick_user(){
    let tick1=document.getElementsByClassName('login')[0];
    let tick2=document.getElementsByClassName('login0')[0];
    tick1.style.display='flex'
    tick2.style.display='none';
}
function tick_administrator(){
    let tick1=document.getElementsByClassName('login')[0];
    let tick2=document.getElementsByClassName('login0')[0];
    tick1.style.display='none';
    tick2.style.display='flex';
}

//忘记密码的提示
document.getElementsByClassName('forget_password')[0].addEventListener('click',()=>{
    alert("请找管理员，亲~");
})

    


//获取输入信息

//接口
//用户登录
   
function Login(){
    let obj={
        username:'',
        password:''
    }
    obj.username=document.getElementsByClassName('user_name2')[0].value; 
    obj.password=document.getElementsByClassName('user_password2')[0].value; 
    axios({
        url:'http://wuxiaoyao.nat100.top/yunqi/loginServlet',
        method:'post',
        data:obj
    }).then((res)=>{
        console.log(res)
        obj.username= res.data.username;
        localStorage.setItem('username',obj.username);
        location.href="../wjq/index.html"
    },error=>{
        console.log(error);
        alert("用户名或密码有误");
    })
}

// 管理员登录
function Login_a(){
    let obj1={
        username:'',
        password:''
    }
    obj1.username=document.getElementsByClassName('user_name20')[0].value; 
    obj1.password=document.getElementsByClassName('user_password20')[0].value; 
    axios({
        url:'http://wuxiaoyao.nat100.top/yunqi/loginServlet',
        method:'post',
        data:obj1
    }).then((res)=>{
            console.log(res);
            user.username=obj1.username;
            localStorage.setItem('username','obj1.username');
            location.href="../xyh/index.html"
        },error=>{
            console.log(error);
            alert("用户名或密码有误");
        })
}

// 注册
function Enroll(){
    let obj2={
        username:'',
        password:'',
        email:'',
        password1:''
    }
    obj2.username=document.getElementsByClassName('user_name2z')[0].value 
    obj2.email=document.getElementsByClassName('email_write')[0].value; 
    obj2.password=document.getElementsByClassName('user_password2z')[0].value; 
    obj2.password1=document.getElementsByClassName('user_password2x')[0].value; 
    // 邮箱格式问题
    var judge1=obj2.email.search(/.com|.cn/);
    var judge2=obj2.email.search(/@qq|@163/);
    var len=obj2.email.length;
    var count1=0,count2=0;
    for(let i=0;i<len;i++){
        if(obj2.email[i]=='@')
            count1++;
        if(obj2.email[i]==".")
            count2++;
    }
    if(count1==1&&count2==1)
        var judge3=1;
    if((judge1==len-3||judge1==len-4)&&(len-judge2==7||len-judge2==8||len-judge2==6)&&judge3==1){
        console.log("成功");
        if(obj2.password===obj2.password1){
        axios({
                url:'http://wuxiaoyao.nat100.top/yunqi/registServlet',
                method:'post',
                data:obj2
        }).then((res)=>{
            console.log(res);
            user.username=obj2.username;
        },error=>{
            console.log(error);
            alert("注册失败");
        })
        }   
        else
            alert("密码不一致，请重新输入");
        }
    else{
        alert("邮箱格式错误！请重新输入");
       }

    //用户名格式问题
    var format=obj2.username(/^[\u4e00-\u9fa5],{0,}$/);
    if(format!=obj2.username){
        alert(用户名中有汉字,请重新输入);
    }
}

//请求拦截器
axios.interceptors.request.use(function (config) {
    // Do something before request is sent 
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });



